//
//  PayFoodStepViewController.m
//  Menu
//
//  Created by dllo on 15/7/7.
//  Copyright (c) 2015年 lijiangang. All rights reserved.
//

#import "PayFoodStepViewController.h"

@interface PayFoodStepViewController ()

@end

@implementation PayFoodStepViewController

- (void)dealloc
{
    [_stepTableView release];
    [super dealloc];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.view.frame = CGRectMake(0, (260+40)*HEIGHT+64, 375, (667-260-40)*HEIGHT-64);
    self.stepTableView = [[UITableView alloc] initWithFrame: CGRectMake(0, 0, 375*WIDTH, (667-260-40)*HEIGHT-64-49) style:UITableViewStylePlain];
    self.stepTableView.backgroundColor = [UIColor whiteColor];
    self.stepTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.stepTableView.bounces = YES;
    [self.view addSubview:self.stepTableView];
    
    self.stepTableView.delegate = self;
    self.stepTableView.dataSource = self;
    
    [_stepTableView release];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.stepArray.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    PayFoodModel *model = [self.stepArray objectAtIndex:indexPath.row];
    CGFloat height = [[self class] heightForcell:model.describe];
    model.height = height;
    return 200*HEIGHT + height + 10*HEIGHT;
}

+(CGFloat)heightForcell:(NSString *)content
{
    //参数1.设置计算内容的宽和高
    //参数2.设置计算高度模式
    //参数3.设置计算字体大小属性
    //参数4.系统备用参数,设置为nil
    //其中宽度一定与显示内容的label宽度一致否则计算不准确  高度尽量大一些
    CGSize size=CGSizeMake(315*WIDTH, 10000);
    //字体大小一定与显示内容的label字体大小一致  默认是17.0
    NSDictionary *dic =[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:17.0] forKey:NSFontAttributeName];
    
    CGRect frame=  [content boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return frame.size.height;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *step = @"stepCell";
    PayFoodStepTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:step];
    if (cell == nil)
    {
        cell = [[PayFoodStepTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:step];
    }
   
    cell.payFoodModel = [self.stepArray objectAtIndex:indexPath.row];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}




























- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
